<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {

    function _initialize(){
        $config=M("config")->find();
        $this->assign("config",$config);
    }

    
    /**
     * 主页 
     * @author 
     */
    public function index(){
        $status["status"]=1;
        $news=M("bulletin");
        $subs=M("subject");
        $line=10;
        $new=$news->where($status)->limit($line)->select();
        $sub=$subs->where($status)->select();
        $this->assign("new",$new);
        $this->assign("sub",$sub);
        $this->display();
    }
    /**
     * app主页 
     * @author 
     */
    public function appindex(){
        $status["status"]=1;
        $news=M("bulletin");
        $subs=M("subject");
        //$line=10;
        $new=$news->where($status)->limit($line)->select();
        $sub=$subs->where($status)->select();
        $this->assign("new",$new);
        $this->assign("sub",$sub);
        $this->display();
    }
    /**
     * 科目页 
     * @author 
     */
    public function book(){
        $status["status"]=1;
        $id["Sub_Code"]=I("get.id");  
        $subs=M("subject");
        $sub=$subs->where($id)->find();
        $sub_sec=M("subject_section");
        $section=$sub_sec->where($id)->select();
        if(IS_POST && IS_AJAX){
            $info=M("resource");
            $sect["sectionID"]=I("post.id");
            $data=$info->where($sect)->select();
            if($data){
                $this->ajaxreturn($data);
            }else{
                $this->ajaxreturn("error");
            }
        }
        $this->assign("section",$section);
        $this->assign("sub",$sub);
        $this->display();
    }
    /**
     * 科目页 
     * @author 
     */
    public function appclass(){
        $status["status"]=1;
        $id["Sub_Code"]=I("get.id");  
        $subs=M("subject");
        $sub=$subs->where($id)->find();
        $sub_sec=M("subject_section");
        $section=$sub_sec->where($id)->select();
        if(IS_POST && IS_AJAX){
            $info=M("resource");
            $sect["sectionID"]=I("post.id");
            $data=$info->where($sect)->select();
            if($data){
                $this->ajaxreturn($data);
            }else{
                $this->ajaxreturn("error");
            }
        }
        $this->assign("section",$section);
        $this->assign("sub",$sub);
        $this->display();
    }
    /**
     * 视频页 
     * @author 
     */
    public function video(){
        if($_GET){
            $resid["resid"]=$_GET["id"];
            $date=M("resource")->where($resid)->getField('respath');
            //var_dump($date);die();
            $this->assign('date',$date);
        }
        $this->display();
    }
    
    /**
     * 公告
     * @author 
     */
    public function news(){
    	$status["status"]=1;
        $news=M("bulletin");
        $info=$news->where($status)->select();
        $this->assign("info",$info);
        $this->display();
    }
    /**
     * 公告详情
     * @author 
     */
    public function news_pop(){
    	$id["id"]=I('get.id');
    	$news=M("bulletin");
    	$info=$news->where($id)->find();
        $this->assign("info",$info);
        $this->display();
    }
    /**
     * 搜索结果
     */
    public function search(){
        $keyword=I('get.keyword');
        $sub=M("subject");
        $map['ChName'] =array('like','%'.$keyword.'%');
        $subs=$sub->where($map)->select();
        $this->assign("subs",$subs);
        $this->display();
    }
}
